package com.hengxinyongli.iam.web.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * @author magic
 * @date 2018/9/25/025 14:16
 * @version 1.0
 * Description Responses
 */
@ApiModel
public class Responses<T> {

    public static final int SUCCESS_CODE = 200;
    public static final int ERROR_CODE = 500;
    public static final int FAIL_CODE = 999;

    @ApiModelProperty(name = "code",value = "接口返回的状态码")
    private Integer code;
    @ApiModelProperty(name = "message",value = "接口返回提示信息")
    private String message;
    @ApiModelProperty(name = "payload",value = "接口返回结果集")
    private T payload;

    public Responses() {
    }

    public Responses(Integer code, String message, T payload) {
        this.code = code;
        this.message = message;
        this.payload = payload;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getPayload() {
        return payload;
    }

    public void setPayload(T payload) {
        this.payload = payload;
    }

    public static Responses success(Object payload){
        return new Responses(SUCCESS_CODE,"",payload);
    }

    public static Responses fail(String message){
        return new Responses(FAIL_CODE,message,null);
    }

    public static Responses fail(Integer code,String message){
        return new Responses(code,message,null);
    }
}
